#include <iostream>
#include<string.h>
using namespace std;
using std::string;
class CharArray {
public:
        CharArray(const char* pstr) {
        if (pstr == nullptr) {  // 处理空指针
            _pstr = new char[1];
            _pstr[0] = '\0';
            return;
        }
        size_t len = strlen(pstr) + 1;
        _pstr = new char[len];
        strcpy(_pstr, pstr);
    }

    char& operator[](size_t index){
        if(index>=strlen(_pstr)){
            static char nullchar='\0';
            return nullchar;

        }
        return _pstr[index];
    }
private:
    char* _pstr;
};
void test(){
    CharArray ca("hello");
    cout<<ca[3]<<endl;
    ca[0]='H';
    cout<<ca[0]<<endl;
}
int main(int argc, char * argv[]){
    test();
    return 0;
}

